package com.javandad.app.client.cells;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.javandad.app.shared.entity.ChatMessage;
import com.javandad.app.shared.entity.User;

public class ChatMessageCell extends AbstractCell<ChatMessage> {
	private User partner;
	public ChatMessageCell(User partner) {
		this.partner = partner; 
	}
	
	@Override
	public void render(Cell.Context context, ChatMessage value, SafeHtmlBuilder sb) {
		boolean sent = value.getReceiverId().equals(partner.getUserId());
		sb.appendHtmlConstant(sent ? "<i>" : "<b>");
		sb.appendEscaped(value.getText());
		sb.appendHtmlConstant(sent ? "</i>" : "</b>");
	}

}
